package com.api.gbhg.hzz;

import com.api.gbhg.lbj.dao.GeneralProjectDao;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import com.api.gbhg.zengping.utils.DateUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
*拱北海关报刊订阅 -->入库经费额度表
*@author hzz
*@date 2020/1/05
*/
public class SynBkJinFeiDataAction implements Action {
    Log log = LogFactory.getLog(SynBkJinFeiDataAction.class);
    @Override
    public String execute(RequestInfo requestInfo) {
        log.info("------------------------------------------进入节点后SynBkJinFeiDataAction-----------------------------------------------------------------");
        String requestId = requestInfo.getRequestid();
        PropertyManagementCostDao p=new PropertyManagementCostDao();
        String sql = "select dt.*,dt2.bmyszcjjfl,dt2.dyzfjjfl,dt2.hjwy from (\n" +
                " select t1.id,t.sbdw,t.xmmin,t.lcbj,t.lcjlsqjlid,t.ysnd,t.jbr,t.gkdw,t.sydw from uf_jingfei_version t,uf_gbhgbkdyspb t1 where t.requestId = '" + requestId + "' and t.requestId = t1.requestId ) dt \n" +
                " left join uf_gbhgbkdyspb_dt2 dt2 on dt2.mainid = dt.id  ;";
        log.info("拼接后的sql : " + sql);
        RecordSet rs = new RecordSet();
        rs.executeQuery(sql);
        Map<String,String> map = new HashMap<>();
        RecordSet recordSet = GeneralProjectDao.deleteWorkflowByid(requestId);
        recordSet.next();
        while (rs.next()){
            map.put("requestId",requestId);
            map.put("sbdw", rs.getStringNoTrim("sbdw"));
            map.put("xmmc", rs.getStringNoTrim("xmmin"));
            map.put("lcbj", rs.getStringNoTrim("lcbj"));
            map.put("lcjlid", rs.getStringNoTrim("lcjlsqjlid"));
            map.put("bmzcjjfl", rs.getStringNoTrim("bmyszcjjfl"));
            map.put("zfjjfl", rs.getStringNoTrim("dyzfjjfl"));
            map.put("nd", rs.getStringNoTrim("ysnd"));
            map.put("ze", rs.getStringNoTrim("hjwy"));
            String syed = "0.00";
            if (rs.getStringNoTrim("hjwy").equals("")) {
                map.put("ze","0.00");
                syed = "0.00";
            }else {
                syed=rs.getStringNoTrim("hjwy");
            }
            map.put("syed", syed);
            map.put("dj", "0.00");
            map.put("modedatamodifier",rs.getStringNoTrim("jbr"));
            map.put("modedatamodifydatetime", DateUtil.getNowDate());
            map.put("gkdw", rs.getStringNoTrim("gkdw"));
            map.put("sydw", rs.getStringNoTrim("sydw"));
            log.info("同步数据集合map : " + map.toString());
            Boolean b = p.insertBudgeLines(map);
            if (!b) {
                requestInfo.getRequestManager().setMessagecontent("报刊订阅(年度增订)入库失败");
                requestInfo.getRequestManager().setMessageid("");
                log.info("同步流程报刊订阅(年度增订)数据到入库表失败！");
                return FAILURE_AND_CONTINUE;
            }
        }

        return SUCCESS;
    }
}
